package ticketmachine.logic.taxCalculatorAdapters;

import java.util.ResourceBundle;

public class TaxCalculatorFactory {
	
	private static TaxCalculatorFactory factory;
	private ResourceBundle configuration;
	
	public TaxCalculatorFactory() {
		try {
			configuration=ResourceBundle.getBundle("ticketmachine.configuration");
		} catch (Exception e) {
			System.out.println("Could not find Configuration File");
		}
	}


	public static TaxCalculatorFactory getInstance(){
		if (factory==null){
			factory=new TaxCalculatorFactory();
		}
		return factory;
	}

	public ITaxCalculator getTaxCalculatorAdapter(){
		ITaxCalculator tc=null;
		String taxCalculatorClass=configuration.getString("taxCalculatorClass");
		try {
			tc=(ITaxCalculator) Class.forName(taxCalculatorClass).newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return tc;
	}

}
